package com.sbtr.business.publishtask.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sbtr.business.publishtask.dto.PublishServerStatisticDto;
import com.sbtr.business.publishtask.entity.PublishAssignData;
import com.sbtr.business.publishtask.mapper.PublishAssignDataMapper;
import com.sbtr.business.publishtask.service.IPublishAssignDataService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 数据类部署任务分配表，记录部署任务分配到哪个部署服务器上 服务实现类
 * </p>
 *

 */
@Transactional
@Service
public class PublishAssignDataServiceImpl extends ServiceImpl<PublishAssignDataMapper, PublishAssignData>
		implements IPublishAssignDataService {

	@Override
	public List<PublishServerStatisticDto> countByServer(List<Long> serverIds) {
		if (CollectionUtils.isEmpty(serverIds)) {
			return Collections.emptyList();
		}
		List<Map<String, Object>> list = baseMapper.countByServer(serverIds);
		List<PublishServerStatisticDto> result = list.stream()
				.map(map -> new PublishServerStatisticDto((Long) map.get("serverId"), (Long) map.get("number")))
				.collect(Collectors.toList());
		Collectors.toList();
		return result;
	}
}
